<!--
 * @Descripttion:
 * @version:
 * @Author: 韩应波
 * @Date: 2020-12-01 09:33:31
 * @LastEditors: 韩应波
 * @LastEditTime: 2021-03-10 09:02:39
-->
<template>
  <div class="app-container">
    <el-form
      ref="listFilterRef"
      :model="list.filter"
      inline
      class="list-filter"
    >
      <el-form-item prop="name">
        <el-input v-model="list.filter.name" placeholder="文件名称" clearable />
      </el-form-item>
      <el-form-item prop="startTime">
        <time-range-picker
          :start.sync="list.filter.startTime"
          :end.sync="list.filter.endTime"
          type="date-time"
          placeholder="保存文档开始时间/保存文档结束时间"
        />
      </el-form-item>
      <!-- type="date-time"  -->
      <el-form-item>
        <el-button @click="reset">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-operation">
      <div>
        <!-- <AuthButton @click="exportList()" name="导出" :loading="exportListLoading" /> -->
      </div>
      <el-pagination
        v-bind="elPaginationProps"
        :total="list.total"
        :currentPage.sync="list.filter.pageNo"
        :pageSize.sync="list.filter.pageSize"
      />
    </div>

    <el-table v-loading="list.loading" :data="list.data" v-bind="tableProp">
      <el-table-column align="center" type="index" />
      <el-table-column label="文档名称" prop="name" />
      <el-table-column label="文档内容时间区间">
        <template slot-scope="{ row }">
          {{ row.startTime }} - {{ row.endTime }}
        </template>
      </el-table-column>
      <el-table-column label="保存文档时间" prop="createTime" />
      <el-table-column label="文档过期时间" prop="expireTime" />
      <el-table-column label="文档状态" prop="status">
        <template slot-scope="{ row: { status } }">
          <el-tag :type="getStatus(status).type">
            {{ getStatus(status).text }}
          </el-tag>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="300">
        <template slot-scope="{ row }">
          <AuthButton
            @click="downloadFile(row)"
            v-if="row.status == 2"
            circle
            name="下载"
            type="success"
          >
            <i class="el-icon-download" />
          </AuthButton>
          <AuthButton
            @click="d({ id: row.id })"
            v-if="row.status != 1"
            name="删除"
          />
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import pageMixin from '@/utils/pageMixin'
import useAdmateAdapter from '@/utils/useAdmateAdapter'

export default {
  mixins: [pageMixin],
  setup: () =>
    useAdmateAdapter({
      urlPrefix: 'sot-admin-api/sys/download',
      axiosConfig: {
        getList: {
          url: 'queryForPage'
        },
        d: {
          method: 'POST'
        }
      },
      list: {
        filter: {
          name: '',
          startTime: null,
          endTime: null
        }
      }
    }),
  data () {
    return {}
  },
  methods: {
    getStatus (status) {
      const statusDict = [
        { text: '生成中', value: 1, type: 'info' },
        { text: '已生成', value: 2, type: 'success' },
        { text: '生成失败', value: 3, type: 'danger' }
      ]
      return statusDict.filter(item => item.value == status)[0] || statusDict[0]
    },
    downloadFile (row) {
      if (row.url) {
        window.location.href = row.url
      } else {
        this.$swal.error('文件信息有误')
      }
    }
  }
}
</script>
